【问题标题】:can i insert string after "this" inside onclick in Javascript?我可以在 Javascript 的 onclick 中的“this”之后插入字符串吗?
【发布时间】:2016-06-03 13:15:08
【问题描述】:

新手在这里问。

我有一个多维数组的有序列表

$blok = array
   (
       array("B","X","X",3,4,5,"X",7,8,9,10),
       array("G",1,2,3,4,5,6,7,8,9,10),
       array("L",1,2,3,4,5,6,7,8,9,10),
       array("Q",1,2,3,4,5,6,7,8,9,10)
   );

然后我将每个数组值回显到单独的 div 中:

*已经知道如何回显它们并将它们插入到 div id 中。



我的问题是:我可以在 onclick 内的“this”之后插入字符串吗?

<div class="span4"><div class="table1" style="float:left; background-color:magenta;" id= "'. //ARRAY VALUE// .'" onclick="select(this,"B");" >

<div class="span4"><div class="table1" style="float:left; background-color:blue;" id= "'. //ARRAY VALUE// .'" onclick="select(this,"Q");" >

我的目标是在 input type=hidden 之后将 div id(数组值)和 string 输入我的数据库强>点击

<input type="hidden" id="type" name="type" value="" />
<input type="hidden" id="table"  name="table" value="" />

感谢任何帮助,我在这里画一个空白。



顺便说一句,这是我的javascript:

var i=0;    document.getElementById("table").value="";    function select(id , tipe){
if($(id).attr('class')=="table2"){
    $(id).attr('class','table1');
    var m=document.getElementById("table").value.split(",");
    var removeItem = $(id).attr('id');;
    var n = jQuery.grep(m, function(value) {
      return value != removeItem;
    });
    document.getElementById("table").value=n;

    if(n.length==0){i=0;}
}else{
    $(id).attr('class','table2');
    if(i==0){
        document.getElementById("table").value+=$(id).attr('id');
        i=1;
    }else{
        var j=document.getElementById("table").value.split(",");    
        if(jQuery.inArray($(id).attr('id'), j)==-1)         {
            document.getElementById("table").value+=","+$(id).attr('id');
        }
    }   
}
var type=document.getElementById('type');
type.value=tipe   }

编辑:我忘了提到我正在使用这样的连接分配:

$number  =' <div class="table1" style="float:left; background-color:magenta;" id= "'. $blok[$row][$col] .'" onclick="select(this,"B");" > ';    
$number  .= $blok[$row][$col]; //echo the array value to display the table number
$number  .=' </div> ';

以便将那些带有 ARRAY VALUE 的 div 显示为 div id要显示的文本 我只写了:

echo $number;

【问题讨论】:

  • 由于您的选择函数有两个参数,因此您可以传递两个值。为什么不提醒它?
  • 它甚至无法在我尝试分配的警报之前运行“将类 table1 更改为 table2”功能

标签: javascript php html


【解决方案1】:

将第二个参数用单引号括起来:

.. onclick="select(this,'B');" ...

为您的 php 代码:

.'" onclick="select(this,'."'B'".');" > ';

【讨论】:

  • 感谢回复,但它调用了这个:语法错误,意外的 T_STRING
  • 对不起,我忘了提到我正在使用连接分配,就像我在那里编辑的帖子一样
猜你喜欢
  • 1970-01-01
  • 2020-11-15
  • 1970-01-01
  • 1970-01-01
  • 2016-12-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-16
相关资源
最近更新 更多