2012-01-26 53 views
1

我想補充我的網頁一些股利和其他tags.I想給唯一的類名這樣的:div類名或更改方法?

dataType: "json", 
      success: function (msg) { 
       var c = eval(msg.d); 
       var html = ''; //'<tbody>'; 
       for (var i = 0; i < c.length; i++) { 
        var className = "questionContainer " + i; 
        html += "<div class=" + className + ">"; 
        html += "<div class=question><b>Question" + (i + 1) + ":</b>" + c[i].Name + "?</div>"; 
        html += "<div class=answers><ul>"; 
        for (var j = 0; j < c[i].Choses.length; j++) { 
         html += "<li> <label><input type=radio name=q1" + i + i + "id=q1-a />" + c[i].Choses[j].Name + "</label></li>"; 
        } 
        html += "</ul></div>"; 
        html += "<div class=btnContainer><div class=prev></div><div class=next><a class=btnNext>Next &gt;&gt;</a></div> <div class=clear></div></div></div>"; 
       } 
       html += '</div>'; 
       // $('#dataTable').empty(); 
       $('.as').append(html); 

      } 
     }); 
    }); 
</script> 
<head> 
    <body> 
     <h1>jQuiz Demo Page</h1> 
     <div class="as"></div> 

    </body> 
</head> 

但我的HTML顯示

<div id="0" class="questionContainer" 0=""> like that how can I fixed? 

空間必須有裏面。

回答

0

你已經有了類的名字後面輸入一個空格,你需要把報價繞着它的下一行...

var className = "questionContainer" + i; 
html += "<div class='" + className + "'>";