admin管理员组

文章数量:1415644

I have the following HTML (simplified and stripped for purposes of this question):

<html>
    <head>
        <title>My page</title>
    </head>
    <body>
        <object id="myExp" class="myClass">
            <param name="bgcolor" value="#ffffff" />
            <param name="wmode" value="transparent" />
            <param name="width" value="560" />
            <param name="height" value="310" />
            <param name="id" value="1535" />
        </object>

        <script type="text/javascript">
            function changeId(id)
            {
                // $('#myExp').
            }
        </script>
    </body>
</html>

What I am trying to do is make the changeId() function work. What it should do is replace my <param name="id" value="1535" /> line above with whatever id is passed into the function. How can I use jQuery (or plain old javascript, if need be) to dynamically change the id of the object/param value?

I have the following HTML (simplified and stripped for purposes of this question):

<html>
    <head>
        <title>My page</title>
    </head>
    <body>
        <object id="myExp" class="myClass">
            <param name="bgcolor" value="#ffffff" />
            <param name="wmode" value="transparent" />
            <param name="width" value="560" />
            <param name="height" value="310" />
            <param name="id" value="1535" />
        </object>

        <script type="text/javascript">
            function changeId(id)
            {
                // $('#myExp').
            }
        </script>
    </body>
</html>

What I am trying to do is make the changeId() function work. What it should do is replace my <param name="id" value="1535" /> line above with whatever id is passed into the function. How can I use jQuery (or plain old javascript, if need be) to dynamically change the id of the object/param value?

Share Improve this question asked Dec 19, 2012 at 16:50 IcemanindIcemanind 48.8k52 gold badges181 silver badges306 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3
function changeId(id) {
   $("#myExp param[name=id]").attr('value', id);
}

changeId(6);

Remember to actually call the function as well.

Unless I'm missing something obvious, this is what you're looking for in jQuery:

$("#myExp [name='id']").val(id);

This appears to work:

function changeId(id) {
    $('#myExp [name=id]').val(id);
}

本文标签: javascriptDynamically changing an object parameter with jQueryStack Overflow