English 中文(简体)
通过 jQuery 设置 HTML < 参数> 元素吗?
原标题:Set HTML <param> element via jQuery?

JS/JQuary Newb在这里!

我存储在变量中的值, 我需要将它插入到与 lt; object> 相关的一个特定的 参数> 元素中。 下面是我希望我能做的示例 :

<script>

    function SetParam(incomingValue){
         $( #baz ).value = incomingValue ;
    }

    $(document).ready (function() {

       // jquery POST happens here, which takes a second or two to complete
       // SUCCESS condition calls SetParam() with a value  

        });
</script>

<object class="foo">
    <param name="bar" value="xyzzy" />
   <param name="baz" value="" id="baz" />
</object>

没有喜悦。 Baz 参数控制着天体的视觉变形方式, 我看不到任何变化来显示我成功地更改了值 。

我不确定是否:

<% 1> A. 我的语法在 SetParam () 中处理“ baz” 参数时是错误的 。

B. 我的语法是好的,但我打SetParam () 时对象已经完成,所以设定 baz 值没有用处

" 强 " C. 上述所有情况

有人能朝正确方向踢我吗?

(如果我的问题包括假想的“ B ” - 是否有办法延迟该 < code_ lt; object> 的装入, 直到我实际设定了 < code_ lt; parameter> 的值, 我所需要的值吗? )

这里有一个相同的"JSFiddidle" 刚刚发现了关于这个和Jsbin。

http://jsfiddle.net/sPhrw/

最佳回答

您需要使用普通笔记本或jQuery:

$( #baz ).val(incomingValue);

$( #baz )[0].value = incomingValue;

document.getElementById( baz ).value = incomingValue; 

function SetParam(incomingValue){
     var $foo = $( <object class="foo"></object> ),
         $bar = $( <param name="bar" value="xyzzy" /> ),
         $baz = $( <param name="baz" value=" + incomingValue + " id="baz" /> );
         $foo.append($bar).append($baz).appendTo(someParent);
}
问题回答

您需要将变量和值转换为您情况中应用的变量和值:

$( document ).ready( function () {
    var obj = $(  <object class="foo"></object>  );
    obj.append(  <param name="bar" value="xyzzy"></param>  );

    $.ajax({
        // other parameters
        success: function (response) {
            obj
                .append(  <param name="baz" value="  + response +  "></param>  )
                .appendTo(  body  );
        }
    });
});




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签