Javascript函数在Sharepoint的HTML编辑器中不起作用
没有jquery。纯javascript。我正在使用Sharepoint html内容编辑器。我已将图片和URL的来源标记为机密。我试图得到它,这样当用户点击其中一个图像时,它会触发函数“打开(此)”,并将创建一个特定url的弹出窗口(模式)。到目前为止,当用户单击两个图像中的一个时,它会弹出窗口,但始终指向机密url。因此,当它应该匹配if语句“open(this)”中的第一个case时,它不会指向该url。是的,我已经检查,以确保我有不同的网址。我也切换了URL,它总是转到机密2!!如果可以的话,请帮忙Javascript函数在Sharepoint的HTML编辑器中不起作用,javascript,html,function,sharepoint,Javascript,Html,Function,Sharepoint,没有jquery。纯javascript。我正在使用Sharepoint html内容编辑器。我已将图片和URL的来源标记为机密。我试图得到它,这样当用户点击其中一个图像时,它会触发函数“打开(此)”,并将创建一个特定url的弹出窗口(模式)。到目前为止,当用户单击两个图像中的一个时,它会弹出窗口,但始终指向机密url。因此,当它应该匹配if语句“open(this)”中的第一个case时,它不会指向该url。是的,我已经检查,以确保我有不同的网址。我也切换了URL,它总是转到机密2!!如果可以
<script type="text/javascript">
function opac(x) {
x.style.opacity=.5;
}
function opac_back(x) {
x.style.opacity=1;
}
</script>
<script type="text/javascript">
var options = {
url: theurl,
title: "Learning_Technology",
allowMaximize: true,
showClose: true,
width: 625,
height: 525,
dialogReturnValueCallback: silentCallback};
function open(x) {
var theurl;
if (x.id == "1") {
theurl = "confidential1";
} else if (x.id == "2") {
theurl = "confidential2";
} else {
}
SP.UI.ModalDialog.showModalDialog(options);
}
function silentCallback(dialogResult, returnValue) {
}
function refreshCallback(dialogResult, returnValue) {
SP.UI.Notify.addNotification('Operation Successful!');
SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);
} </script>
<div style="background-color: rgb(237, 237, 237); width: auto; height: auto;">
<center><h2 style="color: green;">MyLearning Requests</h2></center>
<div style="height: auto; width: auto;">
<center><a href="javascript:open(this)"><img width="164" height="42" border="0" id="1" name="button22694Img" src="confidential" onmouseout="opac_back(this)" onmouseover="opac(this)" alt="" style="opacity: 1;"/></a>  
<a href="javascript:open(this)"><img width="164" height="42" border="0" id="2" name="button27129Img" src="confidential" onmouseout="opac_back(this)" onmouseover="opac(this)" alt="" style="cursor: pointer; opacity: 1;"/></a>
</center>
</div>
</div>
函数opac(x){
x、 不透明度=.5;
}
函数opac_back(x){
x、 不透明度=1;
}
变量选项={
url:theurl,
标题:“学习技术”,
allowMaximize:正确,
showClose:没错,
宽度:625,
身高:525,
dialogReturnValueCallback:silentCallback};
功能打开(x){
var-theurl;
如果(x.id==“1”){
theurl=“机密1”;
}否则,如果(x.id==“2”){
theurl=“机密2”;
}否则{
}
SP.UI.ModalDialog.showModalDialog(选项);
}
函数silentCallback(dialogResult,returnValue){
}
函数refreshCallback(dialogResult,returnValue){
SP.UI.Notify.addNotification('操作成功!');
SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);
}
我的学习请求
您正在调用链接标签上的open(this)
,这将是链接,而不是图像。由于链接没有id
属性,您正在将undefined
与“1”和“2”进行比较,这两个属性都将失败。您必须进行一些小的DOM遍历才能获得链接中的图像:)
a标记上没有任何id属性
您正在更新var theurl,但未更新options.url
function open(x) {
var theurl,
img = x.firstChild;
if (img.id == "1") {
theurl = "confidential1";
} else if (x.img == "2") {
theurl = "confidential2";
} else {
}
SP.UI.ModalDialog.showModalDialog(options);
}