dsajdgjadwqe3247382 2013-01-24 13:08
浏览 38
已采纳

将php / mysql值传递给div,可以从javascript访问

I am creating a <div> that represents a table row in sql, with php. Fine. Then I am using a javascript function to test the values of the div (position, width etc).Fine. But I need to pass another value to the div to be checked by the function. It is there in the database but I don't know if there is a (simple) way to do it. Ideally it would look something like this.

<div id='plumber5' class='plumber' style='width:50px;left:100px' value='numericValue'>Derek</div>

The inline styles are generated in php, and can't think of a way of passing a numeric value other than by style (width, height etc) that js can detect.

eg.

<script>
a=document.getElementById('plumber5');
if (a.style.width=>75){
execute something here}
</script>

Instead of using style as a source for testing

Its very troubling! Thanks

EDIT - solution

function checkData($type){  
    a = document.getElementsByClassName($type);
    for(i = 0; i < a.length; i++)
    {
    if (a[i].getAttribute('data-dob') >= sessionStorage.Value) {
    // execute something here
    }
    }

}
  • 写回答

4条回答 默认 最新

  • doushishi6513 2013-01-24 13:11
    关注

    You can use the data attribute of HTML5 to add some custom data to your HTML tags:

    http://ejohn.org/blog/html-5-data-attributes/

    Example:

    <div data-value='10' id='plumber5' class='plumber' style='width: 50px; left: 100px;'>
        Derek
    </div>
    

    You can get the value like this:

    <script>
        a = document.getElementById('plumber5');
        if (a.getAttribute('data-value') => 75) {
            // execute something here
        }
    </script>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 请求分析基于spring boot+vue的前后端分离的项目
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥200 关于#c++#的问题,请各位专家解答!网站的邀请码
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?