Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.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 如何根据输入过滤图像_Javascript - Fatal编程技术网

Javascript 如何根据输入过滤图像

Javascript 如何根据输入过滤图像,javascript,Javascript,因此,我正在为学生们建立一个网站,帮助他们找到对他们有帮助的书籍,我制作了书籍的图片链接,并尝试根据输入过滤图像,但我不能,到目前为止,我就是这么做的 <!DOCTYPE html> <html> <head> <script> function test(){ window.prompt("test") }

因此,我正在为学生们建立一个网站,帮助他们找到对他们有帮助的书籍,我制作了书籍的图片链接,并尝试根据输入过滤图像,但我不能,到目前为止,我就是这么做的

<!DOCTYPE html>
<html>
    <head>
        <script>
            function test(){
                window.prompt("test")
            }
        const books = [
        {
            name: 'Tonguc',
            id: 'ton',
        },
        {
            name: 'Nitelik',
            id: 'Nitelik',
        },
        {
            name: 'Supara',
            id: 'Supara'
        },
        ]

const correctNameBooks = books.filter(book => book.name === test);
console.log(correctNameBooks) 
        </script>
    </head>
    <body>
        <button id="btn" onclick="test()">test</button>
        <img id="ton" src="img/tonguc.PNG">
        <img id="Nitelik" src="img/nitelik.PNG">
        <img id="Supara" src="img/supara.PNG">
    </body>
</html>

功能测试(){
窗口提示(“测试”)
}
常数书=[
{
名称:'Tonguc',
id:'吨',
},
{
名称:“尼泰利克”,
id:'尼泰利克',
},
{
名称:“苏帕拉”,
id:‘苏帕拉’
},
]
const correctNameBooks=books.filter(book=>book.name==test);
console.log(正确的NameBooks)
测试

我能想到的唯一一件事是打印脚本中的图像

我能想到的唯一一件事是打印脚本中的图像

必须将在提示窗口中输入的结果放入
测试
变量中,以便在过滤器中使用此值

<!DOCTYPE html>
<html>

<head>
<script>
    function test() {
        const test = window.prompt("test");
        const correctNameBooks = books.filter(book => book.name === test);
        console.log(correctNameBooks);
    }

    const books = [
        {
            name: 'Tonguc',
            id: 'ton',
        },
        {
            name: 'Nitelik',
            id: 'Nitelik',
        },
        {
            name: 'Supara',
            id: 'Supara'
        },
    ]

</script>
</head>

  <body>
    <button id="btn" onclick="test()">test</button>
    <img id="ton" src="img/tonguc.PNG">
    <img id="Nitelik" src="img/nitelik.PNG">
    <img id="Supara" src="img/supara.PNG">
  </body>
</html>

功能测试(){
常量测试=窗口提示(“测试”);
const correctNameBooks=books.filter(book=>book.name==test);
控制台日志(正确的名称簿);
}
常数书=[
{
名称:'Tonguc',
id:'吨',
},
{
名称:“尼泰利克”,
id:'尼泰利克',
},
{
名称:“苏帕拉”,
id:‘苏帕拉’
},
]
测试

您必须将在提示窗口中输入的结果放入
测试
变量中,以便在过滤器中使用此值

<!DOCTYPE html>
<html>

<head>
<script>
    function test() {
        const test = window.prompt("test");
        const correctNameBooks = books.filter(book => book.name === test);
        console.log(correctNameBooks);
    }

    const books = [
        {
            name: 'Tonguc',
            id: 'ton',
        },
        {
            name: 'Nitelik',
            id: 'Nitelik',
        },
        {
            name: 'Supara',
            id: 'Supara'
        },
    ]

</script>
</head>

  <body>
    <button id="btn" onclick="test()">test</button>
    <img id="ton" src="img/tonguc.PNG">
    <img id="Nitelik" src="img/nitelik.PNG">
    <img id="Supara" src="img/supara.PNG">
  </body>
</html>

功能测试(){
常量测试=窗口提示(“测试”);
const correctNameBooks=books.filter(book=>book.name==test);
控制台日志(正确的名称簿);
}
常数书=[
{
名称:'Tonguc',
id:'吨',
},
{
名称:“尼泰利克”,
id:'尼泰利克',
},
{
名称:“苏帕拉”,
id:‘苏帕拉’
},
]
测试