Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.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
使用Jquery将文本文件加载到Div_Jquery_Text_Hyperlink - Fatal编程技术网

使用Jquery将文本文件加载到Div

使用Jquery将文本文件加载到Div,jquery,text,hyperlink,Jquery,Text,Hyperlink,我创建了以下脚本: <script>function txtload () {$(".divbody").load("maintxt/information1.txt");}</script> $("a.some_class_for_these_links").on("click", function (e) { e.preventDefault(); $(".divbody").load( this.href ); }); 函数txtload()

我创建了以下脚本:

  <script>function txtload () {$(".divbody").load("maintxt/information1.txt");}</script>
$("a.some_class_for_these_links").on("click", function (e) {
    e.preventDefault();
    $(".divbody").load( this.href );
});
函数txtload(){$(“.divbody”).load(“maintxt/information1.txt”);}
我使用的链接如下:

<a href="#" onclick="ChangeImage(), txtload ()">Information 1</a>

我需要更改脚本以创建多个href,为每个链接加载不同的文本:

<a href="#" onclick="ChangeImage(), txtload ()">Information 1</a>
<a href="#" onclick="ChangeImage(), txtload ()">Information 2</a>
<a href="#" onclick="ChangeImage(), txtload ()">Information 3</a>
<a href="#" onclick="ChangeImage(), txtload ()">Information 4</a>

你能帮忙吗?我尝试从脚本中删除“”并将其放在href中…不知道我在做什么

我认为这应该行得通。请给我你的意见:

<script>function txtload () {$(".divbody").load("maintxt/" + filename);}</script>

<a href="#" onclick="ChangeImage(), txtload ("information1.txt")">Information 1</a>
函数txtload(){$(“.divbody”).load(“maintxt/”+filename);}

谢谢

您可以使用一个参数

<script>
    function txtload ( url ) {
        $(".divbody").load( url );
    }
</script>
然后这个html

<a href="your url" class="some_class_for_these_links">Information 1</a>

如果您要使用jQuery,那么将内联脚本与
onclick一起使用是没有意义的

为链接指定一个公共类,您可以使用
href
指定要加载的文件

<a href="maintxt/information1.txt" class="load_link">Information 1</a>
如果用户禁用了javascript,他们仍然可以访问数据,因为它位于
href
中,单击链接将允许他们查看文本文件。搜索引擎机器人也将如此

<a href="your url" class="some_class_for_these_links">Information 1</a>
<a href="maintxt/information1.txt" class="load_link">Information 1</a>
$(function(){

   $('.load_link').click(function(){
       ChangeImage();
       /* "this" is actual link clicked*/
       $(".divbody").load(this.href);
        /* prevent browser opening new page*/
        return false;

  })
})