简体   繁体   English

如何更改html <param> 使用JavaScript的value属性,当它还有runat =“server”时

[英]How do I change an html <param> value attribute with JavaScript when it also has runat=“server”

I am working with a Silverlight application, that when loaded into the browser, it sets an html <param> tag (which is within the silverlight <object> tag) with a value. 我正在使用Silverlight应用程序,当加载到浏览器中时,它会设置一个带有值的html <param>标记(在silverlight <object>标记内)。 Later on during the execution of the SL application, I need to change the value attribute of the <param> tag. 稍后在执行SL应用程序期间,我需要更改<param>标记的value属性。 I'm trying to accomplish this by simply calling a client side javascript function that gets the param tag by it's id, and then call objById.setAttribute(value,"my new value"). 我试图通过简单地调用客户端javascript函数来实现这一点,该函数通过它的id获取param标记,然后调用objById.setAttribute(value,“my new value”)。 Here's where it gets strange. 这是奇怪的地方。 Setting the attribute this way seems to work, according to an alert message displaying the value of the attribute AFTER setting it to the new value. 以这种方式设置属性似乎有效,根据显示属性值AFTER将其设置为新值的警报消息。 However, when I view source on the browser after dismissing the alert dialog, I'm still seeing the old value in the source of the webpage. 但是,当我在解除警报对话框后在浏览器上查看源代码时,我仍然看到网页源中的旧值。 Any idea why the source view wouldn't show the new value? 知道为什么源视图不会显示新值吗? The param tag does have a runat="server" attribute on it because it's initially set by the Silverlight application when it loads. param标签上有一个runat="server"属性,因为它最初是由Silverlight应用程序在加载时设置的。 Does the runat=server attribute cause problems here? runat = server属性是否会导致问题?

HTML: HTML:

<div id="silverlightControlHost">
  <object id="silverlightObject" data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
    <param .../>
    <param .../>
    <param .../>
    <param name="initParams" id="Ip" runat="server" />
    ...

Javascript: 使用Javascript:

function refreshInitParams(newParams) {
  var slObjIp = document.getElementById("Ip");

  //Display Initial Value
  alert(slObjIp.getAttribute("value").toString());
  //Set New Value
  slObjIp.setAttribute("value", "New Value");
  //Display new value
  alert(slObjIp.getAttribute("value").toString());
}

When HTML is parsed, the browser builds a Document Object Model (DOM) out of the raw text. 解析HTML时,浏览器会根据原始文本构建文档对象模型 (DOM)。 This is somewhat analogous to compiling a computer program, as it organizes the information in a way where the browser can quickly find information it needs and make the overall browser experience smooth. 这有点类似于编译计算机程序,因为它以浏览器可以快速查找所需信息的方式组织信息,并使整个浏览器体验流畅。 For example, if you call document.getElementById() , the browser isn't going to re-parse all that HTML again, it's simply going to look in an index of IDs (probably a hash table) for the element in question. 例如,如果您调用document.getElementById() ,浏览器将不会再次重新解析所有HTML,它只是查找相关元素的ID索引(可能是哈希表)。

For this reason, when you update a DOM element, using setAttribute in your case, the browser only updates the DOM. 因此,当您更新 DOM元素时,在您的情况下使用setAttribute ,浏览器只更新DOM。 It has no reason to re-generate the HTML the DOM was built from; 它没有理由重新生成构建DOM的HTML; this would be pointless and create an unnecessary expense. 这将毫无意义,并造成不必要的开支。 For this reason, you won't see any DOM changes reflected if you look at the browser source. 因此,如果查看浏览器源,您将看不到任何DOM更改。 You'll only see the source as it originally came from the server. 您将只看到源最初来自服务器的源。

Hope this helps! 希望这可以帮助!

I assume you're using "View Source" in IE. 我假设您在IE中使用“查看源代码”。
The source of the page will not change after it has loaded. 加载后页面的来源不会改变。 Even changing text on the page via javascript will not show while viewing source. 在查看源代码时,即使通过javascript更改页面上的文本也不会显示。

If you wish you to see source changes on the fly, use Inspect Element in another browser such as Chrome. 如果您希望动态查看源更改,请在另一个浏览器(如Chrome)中使用Inspect Element。 It will show you any changes made via scripts. 它将显示通过脚本所做的任何更改。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 runat=server时如何设置隐藏字段的value属性 - How to set the value attribute of a hidden field when runat=server 如何从 javascript 访问 HTML 控件 runat 服务器 - How can I access to an HTML control runat server from javascript 在ASP中设置为runat =“server”时,html textarea忽略javascript - html textarea ignoring javascript when set to runat=“server” in ASP 如果具有runat =“ server”属性,如何使div可拖动 - How I can make a div draggable if this have the runat=“server” attribute 如何在无法将此代码添加到 HTML 按钮的情况下触发 runat=&quot;server&quot;? - How do I trigger runat=“server” without having access to add this code to the HTML button? 如何使用 javascript 访问 runat="server" ASP 元素? - How can I access runat="server" ASP element using javascript? 如何将html属性值添加到javascript变量中 - How do I add html attribute value into a javascript variable 如果我写了runat =“ server”,则说明JavaScript代码错误 - Error in javascript code if I wrote runat=“server” 如何将JSON数组从文本/ JavaScript块传递到精确目标/ Salesforce营销云中的runat = server块? - How do I pass a JSON array from a text/javascript block to a runat=server block in exacttarget/salesforce marketing cloud? 当我关联runat =“ server”属性时,jQuery UI按钮集不适用于单选按钮 - JQuery UI buttonset not working on radio buttons when I associate runat=“server” attribute
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM