dantebradshaw/phscript
Composer 安装命令:
composer require dantebradshaw/phscript
包简介
use PHP to write JavaScript
关键字:
README 文档
README
Composer package to write JavaScript using PHP.
See more on the composer website
Installation
Run this to install the package:
composer require dantebradshaw/phscript
Example
<!--Consider the following HTML --> <form> <input type="text" name="test" /> <input type="text" id="text" /> <input type="submit" /> </form>
<?php $script = new \DanteB\App\PhScript; $script->startScript(); // <script> $script->select('#text')->console()->end()->print(); // console.log(document.querySelector('#text')); $changeEvent = $script->console('this')->string(); // console.log(document.querySelector(this)) <- but saved as a PHP string $script->select('#text')->listener('change', $changeEvent)->end()->print(); // document.querySelector('#text').addEventListener('change', console.log(document.querySelector(this))); $eachEvent = $script->select('#text')->alert('An alert for every input!')->string(); // alert(document.querySelector('#text')) <- but saved as a PHP string $script->selectAll("input[type='text']")->forEach($eachEvent)->end()->print(); // document.querySelectorAll("input[type='text']").forEach(function () { alert('An alert for every input!') }); $script->endScript(); // </script> ?>
results in javascsript running without ever really needing to write any javascript. Of course, you'll want to put the scripts in the <head> or end of <body> in the document as you would a normal JS file.
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-04-24