简体   繁体   English

如何在jquery中将变量附加到单选按钮的id

[英]how to append a variable to id of radio button in jquery

i have a variable that holds a value and i want to pass this variable as the id of a radio button but when i aspect the element, the value of the id in the radio button is num not 1. 我有一个保存值的变量,我想将此变量作为单选按钮的id传递,但是当我确定元素的高度时,单选按钮中id的值不是num。

 var num=1; 
  $("ol").append("<li> <input type='radio' id=num />  <textarea  rows='2' cols='3'>  </textarea>  <a href='javascript:void(0);' class='remove'><img class='delete' src='images/cross.png' width='16' height='16' border='0'></a></li>");

You mean to do this: 您的意思是这样做:

var num = 1; 
$("ol").append("<li> <input type='radio' id='" + num + "' /> ... "); 

Perhaps something like this is more jQuery 也许像这样的东西更多的是jQuery

var num = 1;
$("ol").append("<li />").append(
  $("<input />", {
    "type": "radio",
    "id": num
  }).append(
    $("<textarea/>", {
      "rows": 2,
      "cols": 3
    })
  ).append(
    $("<a/>", {
      "href": "javascript: void(0)",
      "class": "remove"
    }).append(
      $("<img/>", {
        "class": "delete",
        "src": "images/cross.png",
        "width": 16,
        "height": 16,
        "border": 0
      })
    )
  )
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM