2012-05-02 123 views
1

我正在尝试将单击事件添加到SharePoint中的链接。 由SharePoint设置的当前href为href="javascript:ClickOnce()"。 如果我添加以下代码:使用JavaScript更改href

var saveNclose = document.getElementById("diidIOSaveItem"); 
saveNclose.href = "javascript:JSEPreSaveAction()"; 
alert(saveNclose.href); 

警报输出我想要得到的,这是javascript:PreSaveAction()在href但是当我看它的页面仍然是ClickOnce()

为什么警报告诉我href是一回事,源代码和行为是另一回事?有什么东西导致SharePoint脚本优先于我的吗?

+0

你是如何查看源代码的? – j08691

+0

在Internet Explorer中按F12 –

+0

奇怪的是,我几乎能够完成你在这里成功的工作:http://jsfiddle.net/xZ6nC/。有没有错字:'diidIOSaveItem'应该是'didIOSaveItem'?虽然如果是这样,并且'diidIOSaveItem'不存在,你只会得到一个JS错误,告诉你'null'没有属性'href' ... –

回答

0

我能够加入一个计时器添加PreSaveAction()到按钮的页面装载结束10秒后做到这一点。

0
document.getElementById("diidIOSaveItem").setAttribute("href", "javascript:JSEPreSaveAction()"); 

alert(document.getElementById("diidIOSaveItem").getAttribute("href")); 
+0

刚刚测试过,得到了同样的结果。它警告JSEPreSaveAction()但href仍然是ClickOnce() –

+0

@JonathanEckman,编辑了一下代码。 – Nadh

+0

结果仍然相同。 –