开发者

put a value Inside name in input?

开发者 https://www.devze.com 2023-04-01 19:57 出处:网络
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?

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

精彩评论

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