duangang3832 2016-02-22 07:35
浏览 20
已采纳

我可以在Javascript中点击“this”后插入字符串吗?

newbie asking here.

i have an ordered list of multi dimensional array

$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)
   );

and then i echo each and every array value into separate div :

*already figured it out how to echo them and insert them into div id.



my question is : can i insert string after "this" inside onclick ?

<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");" >

my goal is to input the div id (the array value) and the string into my database using input type=hidden after onclick

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

any help is appreciated, i'm drawing a blank here.



btw this is my 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   }

edit : i forgot to mention i'm using concatenation assignment like this :

$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> ';

so to display those div with ARRAY VALUE as div id and text to display i only wrote :

echo $number;
  • 写回答

1条回答 默认 最新

  • douzhi4056 2016-02-22 07:43
    关注

    Wrap the second argument into a single quotes:

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

    for your php code:

    .'" onclick="select(this,'."'B'".');" > ';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Windows Script Host 无法找到脚本文件"C:\ProgramData\Player800\Cotrl.vbs”
  • ¥15 matlab自定义损失函数
  • ¥15 35114 SVAC视频验签的问题
  • ¥15 impedancepy
  • ¥15 求往届大挑得奖作品(ppt…)
  • ¥15 如何在vue.config.js中读取到public文件夹下window.APP_CONFIG.API_BASE_URL的值
  • ¥50 浦育平台scratch图形化编程
  • ¥20 求这个的原理图 只要原理图
  • ¥15 vue2项目中,如何配置环境,可以在打完包之后修改请求的服务器地址
  • ¥20 微信的店铺小程序如何修改背景图