获得img的价值

时间:2012-08-12 05:42:05

标签: php javascript html css ajax

我不确定你是否可以这样做,但如果没有,请尽可能简单地为我提供一些工作。我希望用户选择一个img(id为'牛仔'或'巨人')。我想得到这些(它们都是'One')的价值并将其返回到id'场景'中。除了这部分之外,其他所有工作都有效,我觉得这是你无法做到的。所以任何建议都会被折旧!

        <script type="text/javascript">
        //this is the user id session stored as a javascript variable
        var userid = "<?=$id?>";

        function bigimg(x) {
            var myDate = new Date(); // Your timezone! 
            var myEpoch = myDate.getTime()/1000; 
            var deadline = '1344700055.000'; 
                //determines if user was on time..if not on time hover enlarge won't work
                if(myEpoch < deadline) {
                    x.style.height="65px";
                    x.style.width="85px";
                    x.style.opacity="0.5";
                } else {}
        }
        function defaultimg(x) {
            x.style.height="60px";
            x.style.width="80px";
            x.style.opacity="1.0";
        }
        function teamback(x) {
            var myDate = new Date(); // Your timezone! 
            var myEpoch = myDate.getTime()/1000; 
            var deadline = '1344700055.000';
                //determines if user was on time..if not on time submitting won't work
                if(myEpoch > deadline) {
                    // update the "actualone" image's source to the sending-image's source
                    document.getElementById("actualone").src = x.src;
                    document.getElementById("curtime").innerHTML = myEpoch;
                    document.getElementById("team").innerHTML = x.id;
                    document.getElementById("team").innerHTML = x.value;
                } else {}           
        }
        </script>

    </head>
        <body>
            Your Team<br>
            <iframe style="background-color:red;" src="http://free.timeanddate.com/countdown/i38ik9yz/n417/cf12/cm0/cu4/ct1/cs1/ca0/co1/cr0/ss0/cac000/cpc000/pct/tc66c/fs100/szw320/szh135/tatTime%20Remaining%20to%20Make%20Picks/tac000/tptTime%20since%20Event%20started%20in/tpc000/iso2012-08-11T13:00:00" frameborder="0" width="236" height="36"></iframe>

            <br><img id="cowboys" value="One" onmouseover="bigimg(this)" onclick="teamback(this)" onmouseout="defaultimg(this)" src="cowboys.gif"> vs <img id="giants" value="One" onmouseover="bigimg(this)" onclick="teamback(this)" onmouseout="defaultimg(this)" src="giants.gif"><img src="" id="actualone" style="width:85px; height:65px;"><br><br>
            <img src="colts.gif"> vs <img src="bears.gif">
            <div id="curtime">44</div>|||<div id="deadline"></div><br><div id="team">Team</div><div id="scenario">Scenario</div>


        </body>
</html>

3 个答案:

答案 0 :(得分:3)

value是一个只能应用于表单元素的属性,例如input。如果您想获得一个简单的属性,请使用name

答案 1 :(得分:1)

更改

document.getElementById("team").innerHTML = x.id;
document.getElementById("team").innerHTML = x.value;

document.getElementById("team").innerHTML = x.id;
document.getElementById("scenario").innerHTML = x.name;

答案 2 :(得分:0)

您还可以使用expando属性,这样您就可以添加自定义属性,例如'value',并使用JavaScript / jQuery读取它。