如何使用 Greasemonkey 更改文本对齐方式?

发布于 2025-01-03 05:39:49 字数 1151 浏览 1 评论 0原文

我想改变这个CSS文本对齐。这是对的,但我希望它被留下。

<div class="btn_gonder" id="ContentPlaceHolder1_btnform">
              <input border="0" type="image" style="height:36px;width:97px;" src="../style/images/btn_gonder.png" alt="Gönder" id="ContentPlaceHolder1_ImageButton1" name="ctl00$ContentPlaceHolder1$ImageButton1"></div>

CSS AREA

.select_container .btn_gonder {
    float: left;
    height: 36px;
    text-align: right;
    width: 304px;
}

HTML AREA

<div class="btn_gonder" id="ContentPlaceHolder1_btnform">
              <input border="0" type="image" style="height:36px;width:97px;" src="../style/images/btn_gonder.png" alt="Gönder" id="ContentPlaceHolder1_ImageButton1" name="ctl00$ContentPlaceHolder1$ImageButton1"></div>

我的代码

我编写了这段代码,但它不起作用...... 如何使用 Greasemonkey 更改文本对齐方式?

<script>
window.onload=allign;
function allign(){
document.getElementById('ContentPlaceHolder1_btnform').style.text-align='left';
}
</script>

I want to change this CSS text-align. it's right but I want it to be left.

<div class="btn_gonder" id="ContentPlaceHolder1_btnform">
              <input border="0" type="image" style="height:36px;width:97px;" src="../style/images/btn_gonder.png" alt="Gönder" id="ContentPlaceHolder1_ImageButton1" name="ctl00$ContentPlaceHolder1$ImageButton1"></div>

CSS AREA

.select_container .btn_gonder {
    float: left;
    height: 36px;
    text-align: right;
    width: 304px;
}

HTML AREA

<div class="btn_gonder" id="ContentPlaceHolder1_btnform">
              <input border="0" type="image" style="height:36px;width:97px;" src="../style/images/btn_gonder.png" alt="Gönder" id="ContentPlaceHolder1_ImageButton1" name="ctl00$ContentPlaceHolder1$ImageButton1"></div>

MY CODE

I wrote this code but it's not work...
How Can i change text-align with Greasemonkey ?

<script>
window.onload=allign;
function allign(){
document.getElementById('ContentPlaceHolder1_btnform').style.text-align='left';
}
</script>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

何以心动 2025-01-10 05:39:49

有几点:

  1. 事件处理程序不能在 GM 脚本中这样设置.

  2. 在支持 GM 的浏览器中以这种方式设置样式时,您需要驼峰式标识符 IE textAlign

  3. 您可能不需要 onload,但我假设在这种情况下,表单不是静态加载(或样式化)的,而是通过 javascript 加载(或样式化)的。

把它们放在一起,你的代码将变成:

window.addEventListener ("load", alignFormText, false);

function alignFormText () {
    var theForm = document.getElementById ('ContentPlaceHolder1_btnform')

    theForm.style.textAlign = 'left';
}

Several things:

  1. <script> tags (or any HTML tags) cannot be used like that in a Greasemonkey script. No variant of <script> is need in this case, anyway.

  2. Event handlers cannot be set that way in GM scripts.

  3. When setting styles that way, in GM-capable browsers, you need the camel-case identifier, IE textAlign.

  4. You probably do not need the onload, but I will presume that in this case the form is not statically loaded (or styled), but loaded (or styled) by javascript.

Putting it all together, your code would become:

window.addEventListener ("load", alignFormText, false);

function alignFormText () {
    var theForm = document.getElementById ('ContentPlaceHolder1_btnform')

    theForm.style.textAlign = 'left';
}
沫尐诺 2025-01-10 05:39:49

您可以这样做:

document.getElementById('ContentPlaceHolder1_btnform').setAttribute("style", "text-align: left;");

This is how you can do it:

document.getElementById('ContentPlaceHolder1_btnform').setAttribute("style", "text-align: left;");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文