存在所以这个问题是问在网上有很多,我看到的答案是检查。长度> 0确定是否包含任何选项选择框使用jQuery
所以在我的情况下,选择框可能或者可能不存在。如果存在,它可能没有选择。
我要为下面的代码:
如果选择框存在...... 如果没有选择框选项... 禁用文本区域
因此我写了下面的:
$(document).ready(function() {
"use strict";
alert('running globals');
// Only process this block if the contactEmailAddress select box exists
if ($('contactEmailAddress').length > 0) {
alert('on the comm page');
// If there are no contacts ...
if ($('#contactEmailAddress option').size() === 0) {
alert('disabling the message box');
$('#message').attr("disabled", "disabled");
}
}
});
问题是,因为选择框没有选项,所以决定selectbox.length为0.所以这个块永远不会触发。
我需要另一种方式。
'$( '#contactEmailAddress选项')。大小()<1'? – Ejaz 2013-04-22 16:27:05