-1
以下代碼用於動態創建複選框。
但在Chrome控制檯中,它表示$未定義。這$錯誤是在這一行:
$.post(
"index1.php",
{
"newopt": newopt
},
完整的代碼在這裏...
var optiondiv = document.getElementById('option-div');
document.getElementById('create').onclick = function() {
newopt = document.getElementById('new-option').value;
if(newopt){
var input = document.createElement('input'),
label = document.createElement('label');
/* IF USER DID NOT INPUT A TEXT, 'No Entered Text' WILL BE THE DEFAULT VALUE */
newopt = (newopt == '')?'No Entered Text':newopt;
/* FILL OUT THE TAGS OF THE NEW INPUT ELEMENT */
input.type = "checkbox";
input.setAttribute("value", newopt);
input.setAttribute("checked", true);
input.setAttribute("name", "prints[]");
/* PUT THE INPUT ELEMENT/RADIO BUTTON INSIDE THE LABEL */
label.appendChild(input);
label.innerHTML += newopt+'<br>';
/* PUT THE LABEL ELEMENT INSIDE THE option-div DIV */
optiondiv.appendChild(label);
//optiondiv.appendChild(input);
//ele.appendChild(input);
//input.onclick = function(){ alert('this is test'); };
//optiondiv.appendChild(label);
document.getElementById('new-option').value = '';
$.post(
"index1.php",
{
"newopt": newopt
},
function(data) {
if(data.success){
alert('Successfully Added To dB');
}else{
alert('Not Added To DB');
}
});
}else{
alert('Please Enter Check Box Value.');
return false;
}
};
這個問題是標記爲 「PHP」 因爲......? – Twinfriends
這不是PHP,但JavaScript和jQuery。你有沒有包含jQuery? – jeroen
你試過用'jQuery'替換'$'嗎? – Cashbee