doupi8598 2019-03-09 12:10
浏览 83
已采纳

Onclick Word替换无法正常使用PHP [关闭]

I have this code:

<a class='show' data-id='".$random."' href='javascript:void(0)' onclick='if(this.innerHTML == 'Click Here to Read More'){this.innerHTML = 'Click Here to Read Less'}else{this.innerHTML = 'Click Here to Read More'}'>Click Here to Read More</a>

When the page is returned though everything is returned weird and items are missing in source code like so:

<a class="show" onclick="if(this.innerHTML == " href="javascript:void(0)" data-id="23272317" }'="" }else{this.innerhtml="Click Here to Read More" more'){this.innerhtml="Click Here to Read Less" read="" to="" here="" click="">Click Here to Read More</a>

Im sure its as simple as a quotes issue but im stuck. Anyone able to point me in the right direction or explain how or why this happens with only javascript?

  • 写回答

1条回答 默认 最新

  • doudong2149 2019-03-09 12:20
    关注

    I suppose you output this code with echo:

    echo "<a class='show' data-id='".$random."' href='javascript:void(0)' onclick='if(this.innerHTML == \"Click Here to Read More\"){this.innerHTML = \"Click Here to Read Less\"} else {this.innerHTML = \"Click Here to Read More\"}'>Click Here to Read More</a>";
    

    Note that I replaced ' around Click Here to ... to escaped " because:

    • ' is already used in enclosing attribute data
    • " enclose full string that you echo
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 openwrt双栈NAT
  • ¥15 部分网页页面无法显示!
  • ¥15 怎样解决power bi 中设置管理聚合,详细信息表和详细信息列显示灰色,而不能选择相应的内容呢?
  • ¥15 QTOF MSE数据分析
  • ¥15 平板录音机录音问题解决
  • ¥15 请问维特智能的安卓APP在手机上存储传感器数据后,如何找到它的存储路径?
  • ¥15 (SQL语句|查询结果翻了4倍)
  • ¥15 Odoo17操作下面代码的模块时出现没有'读取'来访问
  • ¥50 .net core 并发调用接口问题
  • ¥15 网上各种方法试过了,pip还是无法使用