dtntjwkl83750 2014-06-25 21:00
浏览 25

回声一个jquery .remove()函数?

Im creating a blogging system with on page post editing.

If a user is logged in, and they created the blog post then they can see an edit button.

Currently, the edit button is always displayed but is set a display: none for non allowed users.

This works... but ofcourse some one can just change the styling to block with inspector on their browser and viola it works!

I have thought about this and when processing an update in my /updatepost.php page i do another check to see if the user has appropriate access before updating the database.

I dont want however the user to even be able to get this far.

My next idea was instead of setting the button to display none, i would echo a script to remove the button.

I tried e.g.:

if (!isset($userid)) {
    echo '<script> $("#editbutton").remove(); </script>';
}

but that doesnt seem to work.

I could go down the route of creating spans with the user id and the post owner id, then check the value .html() and then check if they match etc. But i prefer my first method.

Any ideas as to where my idea is going wrong?

  • 写回答

4条回答 默认 最新

  • douhao2153 2014-06-25 21:03
    关注

    You are not using it in a document ready. That is probably the root issue. This is getting executed before your page is ready.

    评论

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制