我正在从输入字段发送多个具有相同名称的值。 当我只发送custom1和var 2,但我也想添加一个javascript变量var3,但是使用document.getElemendById分配值时,它会完全覆盖输入字段,并且custom1和var2丢失。因此,如何在末尾添加一个javascript变量var3,使其在数组索引$ pieces [2]下显示;在v.php文件中。
yy <- yy %>%
group_by(fundId) %>%
mutate(StockDiff = apply(yy,2,function(x){
paste(setdiff(unlist(strsplit(x[5], split = ",")), unlist(strsplit(x[4],
split = ","))),collapse = ",")}))
v.php
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<?php $var2 = "custom2" ?>
<form action="v.php" method="POST" >
<input id="jsvar" type="text" name="custom" value="custom1,<?php echo $var2; ?>">
<input type="submit" name="" value="send">
</form>
<script type="text/javascript">
var var3 = "custom3";
document.getElementById("jsvar").value = var3;
</script>
</body>
</html>
答案 0 :(得分:3)
您可以追加数据,而不是用新数据替换。
var var3 = "custom3";
document.getElementById("jsvar").value += ","+var3;
答案 1 :(得分:2)
请在下面尝试。一切正常。在屏幕Link
下查看<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<?php $var2 = "custom2" ?>
<form action="v.php" method="POST" >
<input id="jsvar" type="text" name="custom" value="custom1,<?php echo $var2; ?>">
<input type="submit" name="" value="send">
</form>
<script type="text/javascript">
var pre_value=document.getElementById("jsvar").value;
var var3 = "custom3";
var new_value = pre_value +','+var3;
document.getElementById("jsvar").value = new_value;
</script>
</body>
</html>