Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用jquery mobile防止在所有页面中加载图像_Javascript_Jquery_Jquery Mobile - Fatal编程技术网

Javascript 如何使用jquery mobile防止在所有页面中加载图像

Javascript 如何使用jquery mobile防止在所有页面中加载图像,javascript,jquery,jquery-mobile,Javascript,Jquery,Jquery Mobile,我希望图像出现在窗口/屏幕的不同位置,因此我使用了此功能: function im2(a,b,c,d){ var x = document.createElement("IMG"); x.setAttribute("src", a); x.setAttribute("style",b) x.setAttribute("width", c); x.setAttribute("height&

我希望图像出现在窗口/屏幕的不同位置,因此我使用了此功能:

function im2(a,b,c,d){
 var x = document.createElement("IMG");
  x.setAttribute("src", a); 
  x.setAttribute("style",b)
  x.setAttribute("width", c);
  x.setAttribute("height",d );
  document.body.appendChild(x);
}
因此,我在需要时将这些图像称为

im2("js/image2.jpg","position: fixed; top:210px ; left:165px","280","35")
等等

它在web(没有jqm)上运行良好,在移动应用程序中也运行良好,但是

我使用的是jQuery mobile(1.4.5),图像加载到我的3个页面中(我只需要中间的页面(第2页))。为什么? 我不确定这是刷卡问题还是加载故障

我的页面代码是

 <div data-role="page" id="article3"><!--page3-->
    <div data-role="header" data-theme="b" data-position="fixed" data-id="footer">
      <a href="#article1" data-icon="home" data-iconpos="notext">Home</a>
      <h1>data table</h1>
    </div>
    <div data-role="footer" data-theme="b" data-position="fixed" data-id="footer">
      <h1><-- Back </h1>
    </div>
    <div data-role="content">
      <p>3/3</p>
 ---content---

</div> </div>
我试过了,没用:

$('img').on('dragstart', function(event) {event.preventDefault(); });
或者,同样的,图像仍然出现在所有页面上

$(document).on('swipeleft swiperight', '.selector', function(event) {
 event.stopPropagation();
 event.preventDefault();
});
因此,可能是我没有将这些代码行放在正确的位置,或者可能与刷卡无关。 我找不到任何解决办法,所以我在这里寻求帮助。
谢谢

我觉得你把事情复杂化了。如果要将动态创建的图像放入特定元素,可以更改此行:
document.body.appendChild(x)到这个:
document.querySelector(“#article2”).appendChild(x)

但这会毁掉创建者,因此您可以通过第5个参数来决定要将动态创建的图像放置在何处:

function im2(a,b,c,d,e){
 var x = document.createElement("IMG");
  x.setAttribute("src", a); 
  x.setAttribute("style",b)
  x.setAttribute("width", c);
  x.setAttribute("height",d );
  // this append the image on the body element
  //document.body.appendChild(x);
  //this however will append it on specify id:
  document.querySelector('#'+e).appendChild(x);
}
然后你这样称呼它:

im2("js/image2.jpg","position: fixed; top:210px ; left:165px","280","35",'article2');

@斯图尔特赛德。。。我无法向您发送消息,因此这是我唯一能让您知道我受到了你们两位的启发的方法;,但我仍然无法解决我的问题。。。有没有可能告诉我我是否走上了好的道路?或者@UlrichBangert。。。我无法向您发送消息,因此这是我唯一能让您知道我受到了你们两位的启发的方法;,但我仍然无法解决我的问题。。。“能告诉我我是否走上了正确的道路吗?”deblocker谢谢你的回答,但正如你所看到的,当我调用函数im2时,我提到了位置固定;事实上,我在jqm页面代码中尝试了固定数据位置…但是什么都没有,我的3个页面中都加载了图像非常感谢,这是正确的,我还尝试了使用getelementbyId(#article2)而不是body,效果很好。谢谢你的帮助。
im2("js/image2.jpg","position: fixed; top:210px ; left:165px","280","35",'article2');