http://jsfiddle.net/3QeSe/44/我得到任何帮助的未定义...
答案 0 :(得分:0)
你的textarea没有价值。试试这个:
另外,请尝试在帖子中插入代码,而不是仅在jsfiddle中插入。
您还需要定义元素以使其动态化,可能是通过向元素添加一个类并在与该类匹配的任何元素被修改时获取ID:
<textarea name="text" class="checkthis" id="publiccontent22">Some text here</textarea>
和jQuery:
$(document).ready(function() {
$('.checkthis').blur(function(){
var test = $(this).html();
if (test == '') {
alert("Please Enter Some Text");
}
else {
alert(test);
}
});
});
答案 1 :(得分:0)
您需要使用val()
而不是.html()
来获取textarea
已编辑:(在OP提供更多信息后)
<强>标记:强>
<textarea name="text" class="checkthis" id="publiccontent22">Some text here</textarea>
<强>使用Javascript:强>
$(document).ready(function() {
$('.checkthis').blur(function(){
var test = $(this).val();
if (test == '') {
alert("Please Enter Some Text");
}
else {
alert(test);
}
});
});
答案 2 :(得分:0)
这对我来说很合适http://jsfiddle.net/Zg87Z/
$(document).ready(function() {
var test = $("#publiccontent22").val();
alert(test);
if (test == '') {
alert("Please Enter Some Text");
}
else {
alert(test);
}
});