gpt4 book ai didi

jquery - 使用 jQuery 检查人员选择器字段是否为空?

转载 作者:行者123 更新时间:2023-12-01 06:08:03 25 4
gpt4 key购买 nike

我有以下 HTML

    <tr>
<td>
<div id="ctl00_m_g_c6ae303a_6013_4adb_8057_63a214bcfd24_ctl00_ctl04_ctl08_ctl00_ctl00_ctl04_ctl00_ctl00_UserField_upLevelDiv" TabIndex="0" onFocusIn="this._fFocus=1;saveOldEntities('ctl00_m_g_c6ae303a_6013_4adb_8057_63a214bcfd24_ctl00_ctl04_ctl08_ctl00_ctl00_ctl04_ctl00_ctl00_UserField_upLevelDiv')" onClick="onClickRw(true, true);" onChange="updateControlValue('ctl00_m_g_c6ae303a_6013_4adb_8057_63a214bcfd24_ctl00_ctl04_ctl08_ctl00_ctl00_ctl04_ctl00_ctl00_UserField')" onFocusOut="this._fFocus=0;" onPaste="dopaste();" AutoPostBack="0" class="ms-inputuserfield" onDragStart="canEvt(event);" onKeyup="return onKeyUpRw('ctl00_m_g_c6ae303a_6013_4adb_8057_63a214bcfd24_ctl00_ctl04_ctl08_ctl00_ctl00_ctl04_ctl00_ctl00_UserField');" onCopy="docopy();" onBlur="updateControlValue('ctl00_m_g_c6ae303a_6013_4adb_8057_63a214bcfd24_ctl00_ctl04_ctl08_ctl00_ctl00_ctl04_ctl00_ctl00_UserField')" Title="People Picker" onKeyDown="return onKeyDownRw(this, 'ctl00_m_g_c6ae303a_6013_4adb_8057_63a214bcfd24_ctl00_ctl04_ctl08_ctl00_ctl00_ctl04_ctl00_ctl00_UserField', 3, true, event);" contentEditable="true" style="width: 100%; word-wrap: break-work;overflow-x: hidden; background-color: window; color: windowtext;" name="upLevelDiv">
</div>
<textarea name="ctl00$m$g_c6ae303a_6013_4adb_8057_63a214bcfd24$ctl00$ctl04$ctl08$ctl00$ctl00$ctl04$ctl00$ctl00$UserField$downlevelTextBox" rows="1" cols="20" id="ctl00_m_g_c6ae303a_6013_4adb_8057_63a214bcfd24_ctl00_ctl04_ctl08_ctl00_ctl00_ctl04_ctl00_ctl00_UserField_downlevelTextBox" class="ms-input" onKeyDown="return onKeyDownRw(this, 'ctl00_m_g_c6ae303a_6013_4adb_8057_63a214bcfd24_ctl00_ctl04_ctl08_ctl00_ctl00_ctl04_ctl00_ctl00_UserField', 3, true, event);" onKeyUp="onKeyUpRw('ctl00_m_g_c6ae303a_6013_4adb_8057_63a214bcfd24_ctl00_ctl04_ctl08_ctl00_ctl00_ctl04_ctl00_ctl00_UserField');" Title="People Picker" AutoPostBack="0" style="width:100%;display: none;position: absolute; ">
</textarea></td>
</tr>

我正在尝试检查人员选择器字段是否有任何值,但我无法让它工作(无法使用 ID 属性来查找元素),我不确定要检查哪个元素。

我当前的代码是:

$("input[title=Target Date],input[title=Start Date],select[title=Strategic Objective],select[title=Strategic Priority]").change(function(){
checkControls()
});

在这里我想添加一些类似的内容,select[title=Strategic Priority],textarea.ms-input") 但它不起作用,有什么想法吗?

提前致谢。

编辑:验证代码是:

    //bind a change event to all controls to validate
$("input[title=Target Date],input[title=Start Date],select[title=Strategic Objective],textarea[id$=_UserField_downlevelTextBox],select[title=Strategic

Priority]").change(function(){
checkControls()
});

//the change event function - check the status of each control
function checkControls(){

//set a variable to count the number of valid controls
var controlsPassed = 0;

//set up a selector to pick .each() of the target controls
$("input[title=Target Date],input[title=Start Date],select[title=Strategic Objective],textarea[id$=_UserField_downlevelTextBox],select[title=Strategic

Priority]").each(function(){

//if the control value is not zero AND is not zero-length
var val = $(this).val();
if($(this).is(':hidden') || (val != 0 && val.length != 0)) {

//add one to the counter
controlsPassed += 1;

}
});

//call the PreSaveItem function and pass the true/false statement of 5 valid controls
return (controlsPassed == 5);

}

function PreSaveItem() {
return checkControls()
}

edit2:我想它不起作用,因为其他控件有一个 value 属性。例如,如果我在日期字段中插入某些内容,它们会得到属性值=“18/08/2010”。但是对于文本区域,html 看起来像(简化的)值,那么我如何检查它是否为空?

编辑3:

我变了

return (controlsPassed == 5);

return (controlsPassed == 4) && ( ($("textarea[title='People Picker'][value!='']").length==1) || $("textarea[title='People Picker'][value!='']").is(":hidden") );

但是如果人员选择器被隐藏(.hide()),它仍然想要验证它,所以我想我可以这样做:

if ($("textarea[title='People Picker'][value!='']").is(":hidden")) {
return (controlsPassed == 4)
}
else {
return (controlsPassed == 4) && ( ($("textarea[title='People Picker'][value!='']").length==1);

但是没有,有什么想法吗? }

最佳答案

如果您的 PeopleEditor 的 ID 为 UserField,那么下面的代码应该能够为您选择文本区域。

$(textarea['id$=_UserField_downlevelTextBox'])

下面的代码片段就是您的代码中的内容:

$(textarea['id$=_UserField_downlevelTextBox']).change(function(){
checkControls();
});

关于jquery - 使用 jQuery 检查人员选择器字段是否为空?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3490304/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com