admin管理员组文章数量:1353252
sorry for the question title if it confusing to you. My simple problem is I have an HTML element with an attribute. But I want to concatenate a new value using an event which is onclick. After the user clicked the link the element attribute will be concatenated with my new value ing from my jquery value.
Here's the sample code. By the way I am using smarty.
<a href="products.search.advance&search_by=" class="w024 h024 ml006 b08 u003 d2 f1" id="call_dispatch">
$("#call_dispatch").click(function()
{ldelim}
var dispatch_value = $("#dispatch").val();
var menu = dispatch_value + "|fn_url";
$('#call_dispatch').attr('href',menu);
var x = $('#call_dispatch').attr('href');
alert(x);
{rdelim}
);
Now as you have seen in the href attribute I have a search by value. Now my problem is I need to concatenate this with the var menu value in my jquery. But I don't know how. Please help me guys. Thanks.
sorry for the question title if it confusing to you. My simple problem is I have an HTML element with an attribute. But I want to concatenate a new value using an event which is onclick. After the user clicked the link the element attribute will be concatenated with my new value ing from my jquery value.
Here's the sample code. By the way I am using smarty.
<a href="products.search.advance&search_by=" class="w024 h024 ml006 b08 u003 d2 f1" id="call_dispatch">
$("#call_dispatch").click(function()
{ldelim}
var dispatch_value = $("#dispatch").val();
var menu = dispatch_value + "|fn_url";
$('#call_dispatch').attr('href',menu);
var x = $('#call_dispatch').attr('href');
alert(x);
{rdelim}
);
Now as you have seen in the href attribute I have a search by value. Now my problem is I need to concatenate this with the var menu value in my jquery. But I don't know how. Please help me guys. Thanks.
Share Improve this question asked Oct 29, 2013 at 9:10 JerielleJerielle 7,55029 gold badges103 silver badges168 bronze badges 2- what is $("#dispatch") ? is it a textbox or label or another 'a' tag ? – Ranadheer Reddy Commented Oct 29, 2013 at 9:14
- it is a select option box. – Jerielle Commented Oct 29, 2013 at 10:04
3 Answers
Reset to default 5 var x = $('#call_dispatch').attr('href');
$('#call_dispatch').attr('href',x+menu);
.attr( attributeName, function(index, attr) )
$('#call_dispatch').attr('href', function(index, attr) {
return attr + menu;
});
There is another way to do it. You have to append thet search text to your anchor tag's href when you change the selection.
consider you have select options like below
<select id="dispatch">
<option value="first">first</options>
<option value="second">second</options>
<option value="third">third</options>
</select>
and your anchor tag is
<a href="products.search.advance&search_by=" class="w024 h024 ml006 b08 u003 d2 f1" id="call_dispatch">
now use the following code
$("#dispatch").change(function(){
var dispatch_value = $("#dispatch").val();
var menu = dispatch_value + "|fn_url";
$('#call_dispatch').attr('href',menu);
var x = $('#call_dispatch').attr('href');
alert(x);
});
i created a fiddle. please look at this: http://jsfiddle/codingsolver/bJ4nw/1/
hope it helps you.
本文标签: javascriptHow to concatenate a new value from an existing attribute value using JqueryStack Overflow
版权声明:本文标题:javascript - How to concatenate a new value from an existing attribute value using Jquery? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743861034a2551738.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论