开发者

put a value Inside name in input?

How can I put a value(like: 5 开发者_运维技巧or Etc.) Inside the INPUT => NAME on the checkbox(...name="checkbox[HERE][]"...) after click on button by jQuery?

Html:

<input type="checkbox" name="checkbox[/*HERE*/][]">

Please give me an example in http://jsfiddle.net/ .


Use the attr() method on the element.

$('input').attr('name','checkbox['+value+'][]');


js Fiddle Demo

use .prop because node name is a property. http://api.jquery.com/prop/

$('input:button').click(function(){
    $('input:checkbox').prop('name','checkbox['+10+'][]');
});


Assuming you only have one checkbox on the page:

$('some button selector').click(function(){
  $('input[type=checkbox]').attr('name', 'some value');
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜