1
使用for循环条件动态创建单选按钮时,单选按钮不会创建。我下面的代码是如何使用jquery mobile动态创建单选按钮?
Polldetails.html
<div data-role="content" class="pollsdetailsscreen">
<p>Polls details page with radio buttons created dynamically.</p>
</div>
<div>
<ul id="radiopolls" data-theme="e" >
</ul>
comments:<textarea name="pollscomments" id="pollscomments"></textarea>
<div data-role="content" >
<a href="#" data-role="button" style="width: 100px;float:right">Submit</a>
</div>
</div>
Polldetails.js
var pollsDetails = function pollsDetails(){
//for(var i=0;i<4;i++)
// {
//var radiobutton = document.createElement('label');
//radiobutton.innerHTML="<input type='radio' name='hello'>hii000";
// $('#radiopolls').prepend(radiobutton).trigger('create');
// }
for(var i=0; i<4; i++)
{
if(data.type == "poll")
{
console.log("this is polls page");
//here i need to create four radio buttons dynamically based on below **data** options.
}
else if(data.type == "review")
{
console.log("this is reviews page");
}
}
}
var data = {
type:"poll",
question : "How are you?",
options : [{
type : "radio",
name: "radioTest",
text: "Good"
},
{
type:"radio",
name: "radioTest",
text: "Fine"
},
{
type:"radio",
name: "radioTest2",
text: "Nice"
},
{
type:"radio",
name: "radioTest2",
text: "V Nice"
},
{
type:"checkbox",
name:"check",
text:"This is a check box"
},
{
type:"textarea",
name:"comments",
text:"Comments Please"
}
]
};
作为每代码通过检查条件,我需要动态地创建4个单选按钮时的条件是data.type =“民意调查”,但我无法动态创建基于代码的单选按钮..任何人都可以请帮我这个..........
你能投票答复上一个问题的答案吗? –