简体   繁体   English

JavaScript DOM问题

[英]JavaScript DOM problems

I want to grab value of selectbox with id "rankono" in var h1 and then below that change my iframe src with parts of h1. 我想在var h1中获取ID为“ rankono”的selectbox的值,然后在其下面用h1的一部分更改我的iframe src。 If you see the code I've tried to describe what I'm looking for. 如果您看到该代码,则尝试描述我在寻找什么。

Here is the code I've tried 这是我尝试过的代码

<script>
 var classNumber = document.getElementById('rankdos'); //RANK BILDE 1
classNumber.onchange = runBackgroundChangeDos;

function runBackgroundChangeDos(first){
    var value = first.srcElement.options[first.srcElement.selectedIndex].value;
var h1 = //HERE I LOOOKING FOR WHAT TO TYPE TO GET VALUE OF SELECT WHIT ID rankono
    if (value == 0) {
        document.getElementById('rankimgdos').style.backgroundImage="url('http://localhost/36h8f93.png')"; 
        document.getElementById("PriceFrame").src = "http://www.nordicelite.net/testing/payment.php?crank="h1"&drank=0"; //here i need h1 to show value of select whit id rankono
    } else {
        document.getElementById('rankimgdos').style.backgroundImage="url('http://localhost/rgeg.png')";
    document.getElementById("rankto").innerHTML = "None";
    };
}
</script>

First grab the value 首先抢价值

var h1 = document.getElementById('rankono').value;

then use it like below: 然后像下面这样使用它:

document.getElementById("PriceFrame").src = "http://www.nordicelite.net/testing/payment.php?crank=" + h1 + "&drank=0";

If you want to concatenate a string with a variable in JS, use 如果要在JS中使用变量连接字符串,请使用

var variable = 'bar';
var str = 'Foo' + variable + 'baz';
console.log(str) // Foobarbaz

If your browser supports ES-2015 features, you may use template strings: 如果您的浏览器支持ES-2015功能,则可以使用模板字符串:

var variable = 'bar';
var str = `Foo${variable}baz`;
console.log(str); // Foobarbaz

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM