简体   繁体   English

如何获得

[英]How to get <span id= var

I'm working at a web GUI for an audio mixer. 我正在使用Web GUI进行音频混合。 Therefor I have lot of repetitive faders. 因此,我有很多重复的推子。 All looking the same, just differing by ID. 看起来都一样,只是ID不同。 The ID is a three digit number. ID是一个三位数的数字。 The first digit is provide by the main php page, the other are repetitive in each fader section. 第一位数字由php主页提供,其余的在每个推子部分中重复。 I'm trying to get the result back from the server and posting it into a span field. 我正在尝试从服务器获取结果并将其发布到span字段中。 The problem is that the span id depends on the full id. 问题在于,范围ID取决于完整ID。

The span id should be “result111”.Not hardcoded as it is but dynamically generated by the provide id followed by the identifier 11. 范围ID应该是“ result111”。它不是硬编码的,而是由提供ID和标识符11动态生成的。

 GUI php <script> function transfer(value,id) { if (window.XMLHttpRequest) { // AJAX nutzen mit IE7+, Chrome, Firefox, Safari, Opera xmlhttp=new XMLHttpRequest(); } else { // AJAX mit IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("result"+id).innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","backEnd.php?v="+value+"&id="+id,true); xmlhttp.send(); return; } </script> 
 backEnd.php <?php $id = 10; $value = 7; $result = 6; if ( isset($_GET['id']) ) { $id = $_GET['id']; } if ( isset($_GET['v']) ) { $value = $_GET['v']; $result = $value; } echo ("$id + $result"); ?> GUI.php <?php $id = 1; include 'fader.php'; ?> 
  fader.php <script> var id = <?php echo "$id"; ?>; function setName (id2){ var fullId =""+ id + id2; return fullId; } function setNameReturn (id2){ var fullIdReturn =""+ id + id2; return fullIdReturn; } </script> <form oninput="transfer(auswertung.value,setName(11))"> <input type="range" name="auswertung" min="0" max= "63" value="30" orient="vertical"> <br> <span id="setNameReturn (11)">na</Span> </form> 

You passing value to your function in next way 您以另一种方式将价值传递给函数

transfer(auswertung.value,setName(11))

11 , while expecting 111 11 ,而期待111

is this your problem? 这是你的问题吗?

Update: Just to be clear, everything you generated in PHP stays in PHP, you need to geenrate JS assignment to pass value to JS. 更新:需要明确的是,您在PHP中生成的所有内容都保留在PHP中,您需要了解JS分配以将值传递给JS。 You currently have hardcoded value of 11 at your transfer function, and span result111. 您当前在传递函数中的硬编码值为11,跨度为result111。

This might work or it might not. 这可能有效,也可能无效。 It is just an attempt, because you asked me for it in the comments. 这只是一种尝试,因为您在评论中要求我提供它。 Have a try and see, what happens. 试试看,会发生什么。

GUI.php GUI.php

<?php
$id = 1;

function getSpanId($addedid){
    $spanid = $id + $addedid;
    return $spanid;
}
?>

<script>
function transfer(value,id)
{
    if (window.XMLHttpRequest)
    {
        // AJAX nutzen mit IE7+, Chrome, Firefox, Safari, Opera
        xmlhttp=new XMLHttpRequest();
    }
    else
    {
        // AJAX mit IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
      {
        document.getElementById("result"+id).innerHTML=xmlhttp.responseText;
      }
    }
    xmlhttp.open("GET","backEnd.php?v="+value+"&id="+id,true);
    xmlhttp.send();
    return;
}
</script>

<?php
include 'fader.php';
?>

fader.php fader.php

<form oninput="transfer(auswertung.value,<?php getSpanId(11); ?>)">
    <input type="range" name="auswertung" min="0" max= "63" value="30" orient="vertical">
    <br>
    <span id="<?php getSpanId(11); ?>">n.a.</Span>
</form>

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

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