代码之家  ›  专栏  ›  技术社区  ›  AntonyCatcher

如何在Javascript中通过控制台更改宽度和溢出?

  •  1
  • AntonyCatcher  · 技术社区  · 2 年前

    我是一名iOS开发人员,需要通过JavaScript更改webView iOS应用程序中的一些参数。

    我可以在Safari WebInspector中轻松更改参数,但我需要了解如何更改两个参数 通过WebInspector控制台 .

    我需要在_1Fm4m _1h2dM类中将宽度从100%更改为200vw enter image description here 和 将溢出x更改为在应用程序中可见。

    1 回复  |  直到 2 年前
        1
  •  1
  •   Alexander Nenashev    2 年前

    只需使用 querySelector() Object.assign() 要同时指定多个样式:

    Object.assign(document.querySelector('._1Fm4m._1h2dM').style, {width: '200vw', /* any number of styles you want here */}) && 1
    

    && 1 最终阻止样式对象的输出(一些不需要的噪波),因此您将只得到 1 作为输出。

    与您在第二个案例中使用的方法相同 #app .

    Object.assign(document.querySelector('#app').style, {overflowX: 'visible'}) && 1
    

    为了避免每次在控制台中定义函数时都键入此内容:

    const setStyle = (selector, style) => Object.assign(document.querySelector(selector).style, style) && 1;
    

    然后使用它:

    setStyle('._1Fm4m._1h2dM', {width: '200vw'});
    

    enter image description here

    更持久的方法是将函数添加到代码段中,并在使用之前运行代码段(Ctrl+Enter) setStyle() :

    enter image description here