onclick javascript将值发送到另一个控件
我想将值从EmployeeName发送到sharepoint文本筛选器控件,但使用以下代码时整个页面冻结onclick javascript将值发送到另一个控件,javascript,sharepoint,user-controls,Javascript,Sharepoint,User Controls,我想将值从EmployeeName发送到sharepoint文本筛选器控件,但使用以下代码时整个页面冻结 <div class="ui-widget"> <label for="EmployeeName"> Type Employee Name</label> <input id="EmployeeName"> <input type="button" value="OK" onclick="ja
<div class="ui-widget">
<label for="EmployeeName">
Type Employee Name</label>
<input id="EmployeeName">
<input type="button" value="OK" onclick="javascript:moveValue()" id="btnSearch" name="btnSearch" />
</div>
<script type="text/javascript">
function moveValue() {
var searchTXT = document.getElementById("EmployeeName").value;
document.getElementById("ctl00_m_g_ae01f1bd_e6a3_4044_8045_ab8b29c41f89_SPTextSlicerValueTextControl").value = SearchTXT;
}
<script>
键入员工姓名
函数moveValue(){
var searchTXT=document.getElementById(“EmployeeName”).value;
document.getElementById(“ctl00_m_g_ae01f1bd_e6a3_4044_8045_ab8b29c41f89_SPCTextSlicerValueTextControl”)。值=SearchTXT;
}
我认为您可以做一些事情来改进代码片段
要启动onclick=”“
语法,不需要javascript:
部分,您只在锚定标记hrefs内使用javascript:
,因此将更改为
<input type="button" value="OK" onclick="moveValue()" id="btnSearch" name="btnSearch"/>
看看这是否有帮助。谢谢您的详细回复和代码。让我测试一下,我很快就会更新。一个简单的问题。我可以在填充目标控件后进行回发吗?非常感谢。工作很有魅力。将其添加到函数中,以便使用来自目标控件的新信息回发页面__doPostBack('','')有一个大问题。出于某种原因,代码正在禁用所有sharepoint可单击按钮或链接。如何修复此问题?上述代码不应干扰sharepoint按钮。我会开始检查您的页面是否产生任何Javascript错误(在Firefox或Google Chrome控制台中使用Firebug),任何错误都可能会阻止其他Javascript函数运行并完全停止其他按钮的回发。您是对的。SharePoint运行大量的javascript。如何确保此js不与SP js冲突?滚动条也丢失了,但是如果从页面中取出js(实际上是content editor web部件页面上的链接),那么一切都正常工作
<input id="EmployeeName" type="hidden" value="John Smith" />
function moveValue() {
var employeeField = document.getElementById("EmployeeName");
var otherControl = document.getElementById("ctl00_m_g_ae01f1bd_e6a3_4044_8045_ab8b29c41f89_SPTextSlicerValueTextControl");
//Making sure both fields are not undefined before accessing their properties.
if(employeeField && otherControl){
otherControl.value = employeeField.value;
}else{
//Use for debugging, delete/comment once done
alert("employeeField: " + employeeField + ", otherControl: " + otherControl);
}
}